const https = require("https");
const http = require("http");

http
  .createServer((request, response) => {
    response.writeHead(200, {
      "content-type": "text/html;charset=UTF-8",
    });
    // get方法用于做数据请求
    https.get("https://www.taobao.com", (res) => {
      let result = "";
      let count = 0;
      // 对数据的监听，数据发生改变了，就会触发
      // 它一次只能获取一定量的数据
      res.on("data", (chunk) => {
        // console.log(result);
        result += chunk;
        count++;
      });
      // 监听所有的数据都请求完毕
      res.on("end", () => {
        // console.log(result);
        console.log(count);
        response.write(result);
        response.end();
      });
    });
  })
  .listen(3000);
